package com.shelpe.services.sinbad.service.simbaproxy;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

@FeignClient(name = "${feign.simba.name}", url = "${feign.simba.url}")
@RequestMapping(value = "/simba")
public interface CreativeClient {

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.creative.delete")
	DeleteCreativeResponse deleteCreatives(@RequestParam("nick") String nick,
			@RequestParam("creative_id") long creativeID);

	@Getter
	@Setter
	public static class DeleteCreativeResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_creative_delete_response")
		private DeleteCreativeRes res;
	}

	@Data
	public static class DeleteCreativeRes {
		@JsonProperty("creative")
		private CreativeDto creative;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.creative.add")
	CreateCreativeResponse createCreatives(@RequestParam("nick") String nick,
			@RequestParam("adgroup_id") long adgroupID, @RequestParam("title") String creativeTitle,
			@RequestParam("img_url") String creativeImgUrl);

	@Getter
	@Setter
	public static class CreateCreativeResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_creative_add_response")
		private CreateCreativeRes res;
	}

	@Data
	public static class CreateCreativeRes {
		@JsonProperty("creative")
		private CreativeDto creative;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.creative.update")
	UpdateCreativeResponse updateCreatives(@RequestParam("nick") String nick,
			@RequestParam("adgroup_id") long adgroupID, @RequestParam("creative_id") long creativeID,
			@RequestParam("title") String creativeTitle, @RequestParam("img_url") String creativeImgUrl);

	@Getter
	@Setter
	public static class UpdateCreativeResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_creative_update_response")
		private UpdateCreativeRes res;
	}

	@Data
	public static class UpdateCreativeRes {
		@JsonProperty("creativerecord")
		private CreativeRecordDto creativeRecord;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.creatives.record.get")
	BatchUpdateCreativeResponse batchUpdateCreatives(@RequestParam("nick") String nick,
			@RequestParam("creative_id") List<Long> creativeIDs);

	@Getter
	@Setter
	public static class BatchUpdateCreativeResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_creatives_record_get_response")
		private BatchUpdateCreativeRes res;
	}

	@Data
	public static class BatchUpdateCreativeRes {
		@JsonProperty("creativerecords")
		private List<CreativeRecordDto> creativeRecords;

		public void addCreative(CreativeRecordDto creativeRecordDto) {
			if (this.creativeRecords == null) {
				this.creativeRecords = new ArrayList<CreativeRecordDto>();
			}
			this.creativeRecords.add(creativeRecordDto);
		}
	}

	@Data
	public static class CreativeRecordDto {
		private String nick;
		@JsonProperty("creative_id")
		private long creativeID;
		private String title;
		@JsonProperty("old_title")
		private String OldTitle;
		@JsonProperty("img_url")
		private String image;
		@JsonProperty("old_img_url")
		private String OldImage;
		@JsonProperty("audit_status")
		private String auditStatus;
		@JsonProperty("audit_desc")
		private String auditDesc;

		@JsonProperty("modified_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
		private Date modifiedTime; // 系统记录最后修改时间
		@JsonProperty("create_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
		private Date createTime;

		@JsonProperty("modify_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
		private Date modifyTime; // 创意被修改的时间
	}

	@Data
	public static class CreativeDto {
		@JsonProperty("adgroup_id")
		private Long adgroupId;
		@JsonProperty("creative_id")
		private Long creativeId;
		private String title;
		private String nick;
		@JsonProperty("img_url")
		private String url;

		@JsonProperty("audit_status")
		private String auditStatus;
		@JsonProperty("audit_desc")
		private String auditDesc;

		@JsonProperty("modified_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date modifiedTime;
		@JsonProperty("create_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date createTime;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.creatives.get")
	GetCreativeResponse findCreatives(@RequestParam("nick") String nick, @RequestParam("adgroup_id") long adgroupID);

	@Getter
	@Setter
	public static class GetCreativeResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_creatives_get_response")
		private GetCreativeRes res;
	}

	@Data
	public static class GetCreativeRes {
		@JsonProperty("creatives")
		private CreativeDtos dataList;
	}

	@Data
	public static class CreativeDtos {
		@JsonProperty("creative")
		private List<CreativeDto> creatives;
	}

}
